void CountSort(int* a, int n)
{
	int max = a[0];
	int min = a[0];
	for (int i = 0; i < n; ++i)
	{
		if (max < a[i])
		{
			max = a[i];
		}
		if (min > a[i])
		{
			min = a[i];
		}
	}
	int range = max - min + 1;
	int* cmp = (int*)malloc(sizeof(int*) * range);
	if (cmp == NULL)
	{
		perror("malloc fail");
		return;
	}
	memset(cmp, 0, sizeof(int) * range);
	for (int i = 0; i < n; ++i)
	{
		cmp[a[i] - min]++;
	}
	int j = 0;
	for (int i = 0; i < n; ++i)
	{
		while (cmp[i]--)
		{
			a[j++] = i + min;
		}
	}
	free(cmp);
}
